FROM ubuntu:18.04

ENV ZK_USER=zookeeper \
    ZK_DATA_DIR="/var/lib/zookeeper/data" \
    ZK_DATA_LOG_DIR="/var/lib/zookeeper/log" \
    ZK_LOG_DIR="/var/log/zookeeper" \
    JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" \
    PATH="/opt/zookeeper/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

COPY scripts/pkg_install /usr/bin/

RUN pkg_install tzdata \
 && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ARG ZK_DIST=zookeeper-3.4.14

RUN useradd -md /opt/zookeeper $ZK_USER \
 && pkg_install openjdk-8-jre-headless wget netcat-traditional \
 && wget http://soft.hc-yun.com/base/software/$ZK_DIST.tar.gz -O - | tar xfz - -C /opt/zookeeper --strip-components=1 \
 && apt-get autoremove -y wget \
 && mkdir -p $ZK_DATA_DIR $ZK_LOG_DIR $ZK_DATA_LOG_DIR /tmp/zookeeper \
 && chown -R "$ZK_USER:$ZK_USER" /opt/zookeeper $ZK_DATA_DIR $ZK_LOG_DIR $ZK_DATA_LOG_DIR /tmp/zookeeper

COPY scripts /opt/zookeeper/bin/

USER zookeeper

WORKDIR /opt/zookeeper
VOLUME ["/var/lib/zookeeper"]


ENTRYPOINT ["entrypoint.sh"]

CMD ["zkServer.sh", "start-foreground"]
EXPOSE 2181 2888 3888
